//
//  SortCell.m
//  dyseller
//
//  Created by 红喇叭 on 2017/11/20.
//  Copyright © 2017年 红喇叭. All rights reserved.
//

#import "SortCell.h"

@implementation SortCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if(self){
        [self initView];
    }
    return self;
}

- (void)initView{
    _selectBtn = [[UIButton alloc] init];
    [_selectBtn setImage:[UIImage imageNamed:@"edit_Radio2_default_nor5"] forState:UIControlStateNormal];
    [_selectBtn setImage:[UIImage imageNamed:@"edit_Radio2_default_selected"] forState:UIControlStateSelected];
    [self.contentView addSubview:_selectBtn];
    _selectBtn.sd_layout.leftSpaceToView(self.contentView, GETWITH(20)).widthIs(GETWITH(40)).heightEqualToWidth()
    .centerYEqualToView(self.contentView);
    
    
    _dragBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_dragBtn setImage:[UIImage imageNamed:@"edit_icon2_default_nor"] forState:UIControlStateNormal];
    [self.contentView addSubview:_dragBtn];
    _dragBtn.sd_layout.rightSpaceToView(self.contentView, GETWITH(40)).widthIs(GETWITH(48)).heightEqualToWidth().centerYEqualToView(self.contentView);
    
    _stickBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_stickBtn setImage:[UIImage imageNamed:@"edit_icon1_default_nor"] forState:UIControlStateNormal];
    [self.contentView addSubview:_stickBtn];
    _stickBtn.sd_layout.rightSpaceToView(_dragBtn, GETWITH(40)).widthIs(GETWITH(48)).heightEqualToWidth().centerYEqualToView(self.contentView);
    
    _foodImg = [[UIImageView alloc] init];
    _foodImg.image = [UIImage imageNamed:@"店铺管理_03.png"];
    [self.contentView addSubview:_foodImg];
    _foodImg.sd_layout.
    leftSpaceToView(_selectBtn,GETWITH(30)).
    centerYEqualToView(self.contentView).
    widthIs(GETWITH(120)).heightEqualToWidth();
    
    _defaultImgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"edit_bg2_default_nor"]];
    _defaultImgView.hidden = YES;
    [self.contentView addSubview:_defaultImgView];
    _defaultImgView.sd_layout.leftEqualToView(_foodImg).
    topEqualToView(_foodImg).widthRatioToView(_foodImg, 1).heightEqualToWidth();
    
    _foodName = [[UILabel alloc] init];
    _foodName.textColor = UIColorFromRGB(0x323333);
    _foodName.font = font15;
    //[UIFont fontWithName:@"PingFang-SC-Bold" size:GETWITH(32)];
    [self.contentView addSubview:_foodName];
    _foodName.sd_layout.topEqualToView(_foodImg).leftSpaceToView(_foodImg, GETWITH(36)).autoHeightRatio(0).rightSpaceToView(_stickBtn, GETWITH(20));
    [_foodName setMaxNumberOfLinesToShow:1];
  
    
    _foodPrice = [[UILabel alloc] init];
    _foodPrice.textColor = MianRedColor;
   // _foodPrice.textAlignment = NSTextAlignmentRight;
    _foodPrice.font = font14;
    [self.contentView addSubview:_foodPrice];
    _foodPrice.sd_layout.leftEqualToView(_foodName).
    bottomEqualToView(_foodImg).widthIs(150).heightIs(GETHEIGHT(28));
   
    _foodSales = [[UILabel alloc] init];
    _foodSales.textColor = UIColorFromRGB(0x999999);
    _foodSales.font = font12;
    [self.contentView addSubview:_foodSales];
    _foodSales.sd_layout.leftEqualToView(_foodName).bottomSpaceToView(_foodPrice, GETHEIGHT(10)).widthIs(0).heightIs(12);
    [_foodSales setSingleLineAutoResizeWithMaxWidth:100];
    
    _inventory = [[UILabel alloc] init];
    _inventory.textColor = _foodSales.textColor;
    _inventory.font = _foodSales.font;
    [self.contentView addSubview:_inventory];
    _inventory.sd_layout.leftSpaceToView(_foodSales, GETWITH(20)).bottomEqualToView(_foodSales).rightEqualToView(_foodPrice).heightIs(12);
    
    
}
/*
 goods_name    商品名称
 goods_price    商品价格
 sale_number    销量
 goods_number    商品库存
 no_limit    是否无限库存(0:否;1:是;)
 is_on_sale    是否上架(0:否;1:是;)
 sort    排序
 
 */
- (void)setCategoryContentModel:(CategoryContentModel *)categoryContentModel{
    _categoryContentModel = categoryContentModel;
    _foodName.text = _categoryContentModel.goods_name;
    _foodPrice.text = [NSString stringWithFormat:@"¥%@",_categoryContentModel.goods_price];
    _foodSales.text = [NSString stringWithFormat:@"销量：%@",_categoryContentModel.sale_number];
    [_foodImg sd_setImageWithURL:[NSURL URLWithString:_categoryContentModel.goods_image] placeholderImage:[UIImage imageNamed:@"edit_note2_default"]];
    if([_categoryContentModel.no_limit isEqualToString:@"1"]){
        _inventory.text = @"库存无限";
    }else{
        _inventory.text = [NSString stringWithFormat:@"库存:%@",_categoryContentModel.goods_number]
        ;
    }
    
    if([_categoryContentModel.is_on_sale isEqualToString:@"1"]){
        _defaultImgView.hidden = YES;
        
    }else{
        _defaultImgView.hidden = NO;
    }
    if([_categoryContentModel.is_select isEqualToString:@"0"]){
        _selectBtn.selected = NO;
    }else{
        _selectBtn.selected = YES;
    }
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
